#!/bin/env bash
#
black="\e[30m"
red="\033[31m"
green="\033[32m"
yellow="\033[33m"
blue="\033[34m"
purple="\033[35m"
cyan="\033[36m"
white="\033[37m"
background="\033[0m"

GithubMirror="https://gh.arcticfox.top"

pacman_Syyu(){
if [ -z ${pacman_Syyu} ]
then
  echo -e ${green}正在 ${yellow}更新${background}
  if ! pacman -Syyu --noconfirm --needed
  then
    echo -e ${red}更新出错${background}
    exit 1
  fi
  pacman_Syyu=pacman_Syyued
fi
}

Package=("tar" "gzip" "xz" "tmux" "screen" "wget" "curl" "pv" "git" "redis" "chromium")
for PKG in ${Package[@]}
do
  if ! pacman -Q ${PKG} >/dev/null 2>&1
  then
    echo -e ${green}正在安装 ${yellow}${PKG}${background}
    pacman_Syyu
    until pacman -S --noconfirm --needed ${PKG}
    do
      echo -e ${red}安装失败 3秒后重试${background}
      sleep 3s
    done
    echo -e ${green}安装完成${background}
  fi
done